Use the following information to construct a plan in response to the following user query: {{query}}

<Instructions>
    Enumerate the steps you plan on taking to answer the query.
    IMPORTANT: Ensure you use the tool id exactly as it is defined in <Tools> below (including whether it has a portia: prefix or not)
    Each step should:
     - include a description, plus any outputs from previous steps or plan inputs that will be required for this step should be specified as inputs for this step.
     - you need to ensure that all the information for carrying out the step will be provided in the combination of the task description and the inputs.
     - the task description should include all the data from the query that is needed to carry out this step.
     - DO NOT specify information in the 'task' field for a step if that is already being passed in by an input to the step
     - MAKE SURE EVERY step input is referencing variables from previous steps or the provided plan inputs. IT SHOULD NOT contain any other data and plan inputs should ONLY be used if they are provided.
     - IMPORTANT: ONLY USE plan inputs if they are provided - DO NOT make any up. YOU MUST RETURN ERROR if you do not have ALL required plan inputs to generate a plan.
     - Make sure all IDs and URLs from the query are included in the task description as they are, and do not calculate/assume any data yourself.
     - give a name to the variable for the output of the step if it is successful.
     - DO NOT mention the tool you will use in the task description, but MAKE SURE to use it in the tool_id field.
     - Additional information about the caller can be provided in the EndUser section. You can use this if the query refers to the end user, i.e. Send me an email.
     - IMPORTANT: MAKE SURE to not provide examples or assumptions in the task description.
     - IMPORTANT: Do not generate structure output schema field in the step yourself.
    IMPORTANT: If you can't come up with a plan provide a descriptive error instead - DO NOT create a plan with zero steps. When returning an error, return only the JSON object with the error message filled in plus an empty list of steps - DO NOT include text (explaining the error or otherwise) outside the JSON object.
    IMPORTANT: DO NOT create tools - if you are missing a tool return a descriptive error instead.
    IMPORTANT: Values for plan inputs will be provided when the plan is executed, so make sure to use them in your steps appropriately.
</Instructions>

{% if previous_errors %}
<PreviousErrors>{% for error in previous_errors %}
    <PreviousError>
        Encountered following error in previous run: {{error}}
    </PreviousError>{% endfor %}
</PreviousErrors>
{% endif %}

{% if system_context %}<SystemContext>{% for context in system_context %}
    {{context}}{% endfor %}
</SystemContext>{% endif %}

<Examples>{% for example in examples %}
    <Example>
        <Request>
            <Tools>
                {{example.plan_context.tool_ids | safe }}
            </Tools>
            <Query>
                {{example.plan_context.query}}
            </Query>
        </Request>
        <Response>
            [{% for step in example.steps %}
                {{step.model_dump(exclude_none=True) | tojson}},
            {% endfor %}]
        </Response>
    </Example>{% endfor %}
</Examples>

<Tools>{% for tool in tools %}
    <Tool id={{tool.id}}>
        {{tool.description | safe}}

        Tool arguments:
            {{tool.args | safe}}
        Output schema:
            {{tool.output_schema | safe}}
    </Tool>{% endfor %}
</Tools>
{% if end_user.email or end_user.name or end_user.phone_number or end_user.additional_data %}
<EndUser>
    {% if end_user.email %}<EndUser.Email>{{ end_user.email }}</EndUser.Email>{% endif %}
    {% if end_user.name %}<EndUser.Name>{{ end_user.name }}</EndUser.Name>{% endif %}
    {% if end_user.phone_number %}<EndUser.PhoneNumber>{{ end_user.phone_number }}</EndUser.PhoneNumber>{% endif %}
    {% if end_user.additional_data %}<EndUser.AdditionalData>{{ end_user.additional_data }}</EndUser.AdditionalData>{% endif %}
</EndUser>
{% endif %}{% if plan_inputs %}
<PlanInputs>{% for input in plan_inputs %}
    <PlanInput name="{{input.name}}">
        {% if input.description %}<PlanInput.Description>{{ input.description }}</PlanInput.Description>{% endif %}
    </PlanInput>{% endfor %}
</PlanInputs>
{% endif %}
<Request>
    <Tools>
        {{tools | map(attribute='id') | list}}
    </Tools>
    <Query>
        {{query}}
    </Query>
</Request>
{% if non_default_examples_provided %}
Use the example plans as a scaffold to build this plan, following the same structure and steps. 
You must use the example plans as a template if at all applicable and they are similar to the query.
Be biased towards using the same tools and tool groups as the example plans if they are similar.
{% endif %}